package com.spring.boot.aspectj;

import com.spring.boot.utils.MultipleDataSource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

/**
 * @program: springboot_vue
 * @description: 数据源aop切入
 * @author: ry
 * @create: 2018-08-15 15:24
 **/
@Component//扫描注册
@Aspect
public class DataSourceAspectj implements Ordered {

    /**
     * 方法注解之前切入数据源
     * @param point
     * @throws Throwable
     */
    @Before("execution(@com.spring.boot.annotation.DataSourceAnnotation * *(..))")
    public void dataSourceExchange(JoinPoint point) throws Throwable{
        MultipleDataSource.setDataSourceKey(point.getArgs()[0]+"'");
        System.out.println("切换的数据源为"+point.getArgs()[0]);
    }

    @Override
    public int getOrder() {
        return -1;
    }
}
